@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            @if($type == 'group')
                <a href="{{route('Admin.Home.groupList')}}">活动管理</a>
            @else
                <a href="{{route('Admin.Home.goodsList')}}">商品管理</a>
            @endif
            <em> > </em>
            @if($type == 'group')
                <a href="{{route('Admin.Home.groupGoodsSpuList')}}?goods_id={{$goodsId}}&activity_group_id={{$activityGroupId}}">商品属性列表</a>
            @else
                <a href="{{route('Admin.Home.goodsSpuList')}}?goods_id={{$goodsId}}">商品属性列表</a>
            @endif
            <em> > </em>
            <a href="#">商品属性设置</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="goodsSpu" value="@if($thisGoodsSpu){{$thisGoodsSpu->id}}@endif"/>
                <input type="hidden" name="goods_id" id="goods_id" value="{{$goodsId}}"/>
                <input type="hidden" name="type" id="type" value="{{$type}}"/>
                <input type="hidden" name="activity_group_id" id="activity_group_id" value="@if($type == 'group'){{$activityGroupId}}@endif"/>
                <div class="gg-list">
                    <label class="tit">商品属性名</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品的属性名" name="spu_name" id="spu_name" value="@if($thisGoodsSpu){{$thisGoodsSpu->spu_name}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">商品价格</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品价格" name="price" id="price" value="@if($thisGoodsSpu){{$thisGoodsSpu->price}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（整数或小数）</p>
                    </div>
                </div>

                @if($type == 'group')
                    <div class="gg-list">
                        <label class="tit">商品拼团价格</label>
                        <div class="cont">
                            <input class="gg-ipt" type="text" placeholder="请输入商品价格" name="many_price" id="many_price" value="@if($thisGoodsSpu){{$thisGoodsSpu->many_price}}@endif" /><cite id="title_re" class="required">*</cite>
                            <p class="text">可输入数值（整数或小数）</p>
                        </div>
                    </div>
                @endif
                
                <div class="gg-list">
                    <label class="tit">商品库存</label>
                    <div class="cont">
                        <input type="text" class="gg-ipt" placeholder="请输入商品库存" name="stock" id="stock" value="@if($thisGoodsSpu){{$thisGoodsSpu->stock}} @endif"><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（注意是整数）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">排序</label>
                    <div class="cont">
                        <input type="text" class="gg-ipt" placeholder="请输入排序" name="sort" id="sort" value="@if($thisGoodsSpu){{$thisGoodsSpu->sort}} @endif"><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入整数数值（数值越小越靠前）</p>
                    </div>
                </div>
                
                <div class="gg-list">
                    <label class="tit">状态</label>
                    <div class="cont">
                        <select name="status" id="status">
                            <option value="0" @if($thisGoodsSpu && $thisGoodsSpu->status == 0)selected @endif>停用</option>
                            <option value="1" @if($thisGoodsSpu && $thisGoodsSpu->status == 1)selected @endif>启用</option>
                        </select>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            $(document).on('click', '#btn-set', function () {
                var spuName          = $('#spu_name').val();
                var price            = $('#price').val();
                var goodsId          = $('#goods_id').val();
                var stock            = $('#stock').val();
                var sort             = $('#sort').val();
                var status           = $('#status option:selected').val();
                var type             = $('#type').val();
                var activityGroupId  = $('#activity_group_id').val();
                var manyPrice        = $('#many_price').val();
                var id               = $('#goodsSpu').val();

                $.ajax({
                    url: '{{route("Api.Admin.goods.setGoodsSpu")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        spu_name: spuName,
                        price: price,
                        goods_id: goodsId,
                        stock:stock,
                        sort:sort,
                        status:status,
                        type:type,
                        activity_group_id:activityGroupId,
                        many_price:manyPrice,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        if(type == 'group'){
                                            window.location.href = "{{route('Admin.Home.groupGoodsSpuList')}}?goods_id="+goodsId+'&activity_group_id='+activityGroupId;
                                        }else{
                                            window.location.href = "{{route('Admin.Home.goodsSpuList')}}?goods_id="+goodsId;
                                        }
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: onbj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection